package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Actual_Form_ZongZhongLiang extends BaseActivity {

	protected PictureButton PictureButton_bengshang, PictureButton_bengma;//, PictureButton_bengdan
	protected EditText editText_zongzhongliang, editText_pizhongliang;
	

	@Override
	public void onClick(View view) {
		super.onClick(view);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actual_form_zongzhongliang);
		InitControls();
	}

	protected void onCreate(Bundle savedInstanceState, boolean b) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.actual_form_zongzhongliang);
		//InitControls();
	}	

	@Override
	protected void onResume() {
		super.onResume();
		PictureButton_bengshang.postInvalidate();
		PictureButton_bengma.postInvalidate();
		//PictureButton_bengdan.postInvalidate();	
	}
	@Override
	protected void SaveJsonData() {
		try {
			IsJson1 = true;
			JsonMyID();
			getCar();
			
			//getZhuangdi();
//			getCaiLiao();
			getTask();
			getCurrentUser();
			getZhongLiang();
			getXiedi();
			getGPS();
			getMemo();
//			JsonPicture();
			JsonPicture_Ext();
		}catch (Exception e) {
		}
	}

	protected void getCar() throws JSONException {
		if (editText_car!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_car), editText_car.getText().toString());
			Submit_System_Setting_Data_Task.A_CHEPAI[0] = editText_car.getText().toString();
		}
		if (editText_chexing!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_chexing), editText_chexing.getText().toString());
			Submit_System_Setting_Data_Task.T_CHEXINGHAO = editText_chexing.getText().toString();
		}
	}
	
	protected void getZhongLiang() throws JSONException {
		if (editText_zongzhongliang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_zongzhongliang), editText_zongzhongliang.getText().toString());
			Submit_System_Setting_Data_Task.T_ZONGLIANG = editText_zongzhongliang.getText().toString();
		}		
		if (editText_jingzhong!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_pizhongliang), editText_jingzhong.getText().toString());
		}
		if (editText_gongyingshang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_gongyingshang), editText_gongyingshang.getText().toString());
			Submit_System_Setting_Data_Task.T_SHANGJIA = editText_gongyingshang.getText().toString();
		}
		if (editText_cailiao!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_cailiao), editText_cailiao.getText().toString());
			Submit_System_Setting_Data_Task.T_CAILIAO = editText_cailiao.getText().toString();
		}
	}
	
	protected void JsonPicture_Ext() throws JSONException {
		if (PictureButton_Car!=null) {
			mJson.put( PictureButton_Car.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_Car.mFileName);
		}

		if (PictureButton_CaiLiao!=null) {
			mJson.put( PictureButton_CaiLiao.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_CaiLiao.mFileName);
		}
		if (PictureButton_bengshang!=null) {
			mJson.put( PictureButton_bengshang.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_bengshang.mFileName);
		}
		if (PictureButton_bengma!=null) {
			mJson.put( PictureButton_bengma.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_bengma.mFileName);
		}
//		if (PictureButton_bengdan!=null) {
//			mJson.put( PictureButton_bengdan.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_bengdan.mFileName);
//		}
	}	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_Car, sPath);
			//CopyPicDest(PictureButton_Chexing, sPath);
			CopyPicDest(PictureButton_CaiLiao, sPath);
			CopyPicDest(PictureButton_bengshang, sPath);
			CopyPicDest(PictureButton_bengma, sPath);
			//CopyPicDest(PictureButton_bengdan, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	@Override
	public void Back() {
		super.Back();
	}

	@Override
	public void InitControls() {
		super.InitControls();
		editText_zongzhongliang = (EditText) findViewById(R.id.editText_zongzhongliang);
		editText_pizhongliang =(EditText) findViewById(R.id.editText_pizhongliang);
		
		PictureButton_bengshang = (PictureButton) findViewById(R.id.PictureButton_bengshang);
		PictureButton_bengma = (PictureButton) findViewById(R.id.PictureButton_bengma);
		//PictureButton_bengdan = (PictureButton) findViewById(R.id.PictureButton_bengdan);
		
	}
	
	@Override
	public Boolean IsPassed() {
		if (super.IsPassed()) {
			if(!CheckEditNumber(editText_zongzhongliang))
				return false;
			if (!PictureButton_Car.IsExist()) {
				Utility.MessageBox(this, PictureButton_Car.FIELD );
				return false;
			}
//			if (!PictureButton_Chexing.IsExist()) {
//				Utility.MessageBox( PictureButton_Chexing.FIELD );
//				return false;
//			}		
			if (!PictureButton_CaiLiao.IsExist()) {
				Utility.MessageBox(this, PictureButton_CaiLiao.FIELD );
				return false;
			}
			if (!PictureButton_bengshang.IsExist()) {
				Utility.MessageBox(this, PictureButton_bengshang.FIELD );
				return false;
			}
			if (!PictureButton_bengma.IsExist()) {
				Utility.MessageBox(this, PictureButton_bengma.FIELD );
				return false;
			}
//			if (!PictureButton_bengdan.IsExist()) {
//				Utility.MessageBox( PictureButton_bengdan.FIELD );
//				return false;
//			}			
			return true;
		}else {
			return false;
		}
	}

}
